<template>
    <div>
        <!-- 表头 -->
        <div class="Head" v-if="Head">
            <!-- 仓库名称 -->
            <div class="Cusname">
                <span style="margin-right: 10px">订单号</span>
                <span>
                    <el-input v-model="adi.orderId" placeholder="请输入订单号" clearable></el-input>
                </span>
            </div>
            <!-- 货架名称 -->
            <div class="Cusname">
                <span style="margin-right: 10px">状态</span>
                <span>
                    <el-select v-model="adi.status" placeholder="请选择状态">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                </span>
            </div>
            <!-- 搜索，重置按钮 -->
            <div class="But">
                <el-button type="primary" icon="el-icon-search" @click="serch">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="Reset()">重置</el-button>
            </div>
        </div>
        <!-- 表 -->
        <div class="function" style="margin-top: 10px">
            <el-button type="primary" plain @click="addLists">开始盘库</el-button>
            <el-button type="warning" icon="el-icon-download" plain>导出</el-button>
            <div style="float: right">
                <el-tooltip class="item" effect="dark" content="隐藏搜索" placement="top">
                    <el-button icon="el-icon-search" circle @click="Display"></el-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="刷新" placement="top">
                    <el-button icon="el-icon-refresh" circle @click="Reset"></el-button>
                </el-tooltip>
            </div>
        </div>
        <el-table :data="tableData" class="content" :cell-style="rowClass" :header-cell-style="headClass">
                <el-table-column label="序号" type="index" :index="indexMethod"></el-table-column>
            <el-table-column prop="orderId" label="订单号"></el-table-column>
            <el-table-column prop="createBy" label="盘库人员"></el-table-column>
            <el-table-column prop="createTime" label="盘库时间"></el-table-column>
            <el-table-column label="操作">
                <template>
                    <el-button type="text" size="small" class="el-icon-printer">打印预览</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="block">
            <el-pagination
                background
                style="float: right"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.pageNum"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="page.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            >
            </el-pagination>
        </div>
        <!-- 添加仓库弹框 -->
        <el-dialog title="添加仓库" :visible.sync="dialogVisible" width="55%" :before-close="handleClose" class="adframe">
            <!-- 客户类别 -->
            <div class="Cusgory">
                <span style="margin-right: 10px">所属仓库</span>
                <el-select v-model="adi.wId" placeholder="用户状态" style="margin-top: 10px">
                    <el-option v-for="item in ck" :key="item.wId" :label="item.name" :value="item.wId"></el-option>
                </el-select>
            </div>
             <div class="But">
                <el-button type="primary" icon="el-icon-search" @click="serchs">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="Reset()">重置</el-button>
            </div>
            <div style="float:right;margin-top:10px">
                <el-button type="primary" plain @click="queren">确认盘库</el-button>
            </div>
                <el-table :data="tableDatas" class="content" :cell-style="rowClass" :header-cell-style="headClass">
                <el-table-column label="序号" type="index" :index="indexMethod"></el-table-column>
            <el-table-column prop="number" label="货品编码"></el-table-column>
            <el-table-column prop="name" label="货品名称"></el-table-column>
            <el-table-column prop="stock" label="账面数量"></el-table-column>
            <el-table-column prop="realStock" label="盘点数量" v-if="displays==1">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.realStock"></el-input>
                </template>
            </el-table-column>
            <el-table-column label="差异"  v-if="displays==1">
                 <template slot-scope="scope">
                     {{!scope.row.realStock ? scope.row.stock : scope.row.stock - scope.row.realStock}}
                </template>
            </el-table-column>
            <el-table-column prop="code" label="条形码"></el-table-column>
            <el-table-column prop="brand" label="品牌"></el-table-column>
            <el-table-column prop="spec" label="规格"></el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="block">
            <el-pagination
                background
                style="float: right"
                @size-change="handleSizeChanges"
                @current-change="handleCurrentChanges"
                :current-page="pages.pageNum"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pages.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totals"
            >
            </el-pagination>
        </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dw">取 消</el-button>
                <el-button type="primary" @click="preservation">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { listinve, liststock,listWarehouse, comhp, invead } from '../../api/user.js';
export default {
    data() {
        return {
            // 表头隐藏
            Head: true,
                   // 添加框
            dialogVisible: false,
            tableData: [],
            tableDatas:[],
            //  分页
            page: {
                pageSize: 10,
                pageNum: 1
            },//  分页
            pages: {
                pageSize: 10,
                pageNum: 1
            },
            options: [
                {
                    value: '选项1',
                    label: '请选择字典生成'
                }
            ],
            value: '',
            // 添加输入框
            adi: {},
            ck:[],
            list:[],
            total: null,
            totals:null,
            displays:0
        };
    },
    methods: {
        // 表头显示
        Display() {
            this.Head = !this.Head;
        },
        // 表头样式设置
        headClass() {
            return 'text-align: center;background:#F8F8F9;color:#515A6D;';
        },
        // 表格样式设置
        rowClass() {
            return 'text-align: center;';
        },
        // 分页点击
        indexMethod(index) {
            return (this.page.pageNum - 1) * this.page.pageSize + index + 1;
        },
        // 分页
        handleSizeChange(val) {
            this.page.pageSize = Number(val);
            console.log(`每页 ${val} 条`);
            this.Rean();
        },
        handleCurrentChange(val) {
            this.page.pageNum = Number(val);
            console.log(`当前页: ${val}`);
            this.Rean();
        },

        handleSizeChanges(val) {
            this.pages.pageSize = Number(val);
            console.log(`每页 ${val} 条`);
            this.rean();
        },
        handleCurrentChanges(val) {
            this.pages.pageNum = Number(val);
            console.log(`当前页: ${val}`);
            this.rean();
        },
        // 表格渲染
        Rean() {
            listinve(this.page).then((a) => {
                this.tableData = a.rows;
                this.total = a.total;
            });
        },
        rean() {
            liststock(this.pages).then((res) => {
                console.log(res.total);
                this.tableDatas=res.rows
                this.totals = res.total;
            });
        },
        reans() {
            listWarehouse(this.wId).then((res) => {
                this.ck = res.rows;
                console.log(res.rows);
            });
        },
        // 搜索
        serch() {
            listinve(this.adi).then((res) => {
                console.log(res);
                this.tableData = res.rows;
            });
        },
        serchs() {
            comhp(this.adi).then((res) => {
                console.log(res);
                this.tableDatas = res.rows;
            });
        },
        // 重置按钮
        Reset() {
            this.Rean();
            this.adi.orderId = undefined;
            this.adi.status=undefined
        },
          //   添加弹框
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then((_) => {
                    done();
                })
                .catch((_) => {});
        },
        dw() {
            this.dialogVisible = false;
        },
         //新增按钮
        addLists() {
            this.dialogVisible = true;
            this.Dialogtitle = '添加仓库';
            this.conVar = 0;
        },
        // 确认盘库
        queren(){
            if(this.adi.wId){
                this.displays=1;
                this.Rean()
            }
        },
        // 盘库保存
        preservation(){
            this.tableDatas.forEach((a)=>{
                console.log(a);
                let tableDatas={
                    pId:a.pId,
                    stock:a.stock,
                    category:3,
                    realStock:a.realStock
                };
                this.list.push(tableDatas)
            });
            invead([...this.list]).then((res)=>{
                this.dialogVisible = false;
                console.log(res);
            })
        }
      },
    mounted() {
        this.Rean();
        this.rean();
        this.reans()
    }
};
</script>

<style scoped>
.Head {
    height: 50px;
}
/* 客户类别 */
.Cusgory {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusgory span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 客户名称 */
.Cusname {
    height: 100%;
    float: left;
    margin-right: 10px;
}
.Cusname span {
    display: block;
    height: 100%;
    line-height: 50px;
    font-weight: 800;
    color: #606266;
    float: left;
}
/* 搜素，重置按钮 */
.But {
    height: 100%;
    float: left;
}
.But button {
    margin-top: 10px;
}
</style>